package com.example.myapplication;

import android.os.Parcel;
import android.os.Parcelable;

// 实现Parcelable接口，用于Activity之间传递数据
public class Game implements Parcelable {
    private int id;
    private String name;
    private String description;
    private int iconResId; // 存储图片资源ID

    // 构造方法
    public Game(int id, String name, String description, int iconResId) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.iconResId = iconResId;
    }

    // 以下是Parcelable接口相关方法，用于数据传递
    protected Game(Parcel in) {
        id = in.readInt();
        name = in.readString();
        description = in.readString();
        iconResId = in.readInt();
    }

    public static final Creator<Game> CREATOR = new Creator<Game>() {
        @Override
        public Game createFromParcel(Parcel in) {
            return new Game(in);
        }

        @Override
        public Game[] newArray(int size) {
            return new Game[size];
        }
    };

    // Getter和Setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getIconResId() {
        return iconResId;
    }

    public void setIconResId(int iconResId) {
        this.iconResId = iconResId;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(name);
        dest.writeString(description);
        dest.writeInt(iconResId);
    }
}
